<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>default_allocator</title>
<link rel="stylesheet" href="../../../../../doc/src/boostbook.css" type="text/css">
<meta name="generator" content="DocBook XSL Stylesheets V1.79.1">
<link rel="home" href="../index.html" title="Chapter 1. Boost.Core">
<link rel="up" href="../index.html" title="Chapter 1. Boost.Core">
<link rel="prev" href="cmath.html" title="cmath">
<link rel="next" href="demangle.html" title="demangle">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<table cellpadding="2" width="100%"><tr>
<td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../../../boost.png"></td>
<td align="center"><a href="../../../../../index.html">Home</a></td>
<td align="center"><a href="../../../../../libs/libraries.htm">Libraries</a></td>
<td align="center"><a href="http://www.boost.org/users/people.html">People</a></td>
<td align="center"><a href="http://www.boost.org/users/faq.html">FAQ</a></td>
<td align="center"><a href="../../../../../more/index.htm">More</a></td>
</tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="cmath.html"><img src="../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../index.html"><img src="../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="demangle.html"><img src="../../../../../doc/src/images/next.png" alt="Next"></a>
</div>
<div class="section">
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
<a name="core.default_allocator"></a><a class="link" href="default_allocator.html" title="default_allocator">default_allocator</a>
</h2></div></div></div>
<div class="toc"><dl class="toc">
<dt><span class="section"><a href="default_allocator.html#core.default_allocator.overview">Overview</a></span></dt>
<dt><span class="section"><a href="default_allocator.html#core.default_allocator.examples">Examples</a></span></dt>
<dt><span class="section"><a href="default_allocator.html#core.default_allocator.reference">Reference</a></span></dt>
</dl></div>
<div class="simplesect">
<div class="titlepage"><div><div><h3 class="title">
<a name="idm46136450508880"></a>Authors</h3></div></div></div>
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem">
          Glen Fernandes
        </li></ul></div>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="core.default_allocator.overview"></a><a class="link" href="default_allocator.html#core.default_allocator.overview" title="Overview">Overview</a>
</h3></div></div></div>
<p>
        The header &lt;boost/core/default_allocator.hpp&gt; provides the class template
        <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">default_allocator</span></code> to serve as a minimal
        default allocator that:
      </p>
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
<li class="listitem">
            Like C++2a's <code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">allocator</span></code>, does not provide members
            such as <code class="computeroutput"><span class="identifier">construct</span><span class="special">()</span></code>
            and <code class="computeroutput"><span class="identifier">destroy</span><span class="special">()</span></code>
            to be eligible for optimizations by allocator-aware code that detects
            the absence of these members to provide more optimal construction.
          </li>
<li class="listitem">
            Supports <code class="computeroutput"><span class="identifier">BOOST_NO_EXCEPTIONS</span></code>
            in allocation.
          </li>
<li class="listitem">
            Does not have <code class="computeroutput"><span class="identifier">std</span></code> as
            an associated namespace.
          </li>
</ul></div>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="core.default_allocator.examples"></a><a class="link" href="default_allocator.html#core.default_allocator.examples" title="Examples">Examples</a>
</h3></div></div></div>
<p>
        The following snippet shows the use of this allocator as the default allocator
        for a container.
      </p>
<pre class="programlisting"><span class="keyword">template</span><span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">Key</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">Compare</span> <span class="special">=</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">less</span><span class="special">&lt;</span><span class="identifier">Key</span><span class="special">&gt;,</span>
    <span class="keyword">class</span> <span class="identifier">Allocator</span> <span class="special">=</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">default_allocator</span><span class="special">&lt;</span><span class="identifier">Key</span><span class="special">&gt;</span> <span class="special">&gt;</span>
<span class="keyword">class</span> <span class="identifier">FlatSet</span><span class="special">;</span>
</pre>
<p>
        Facilities like <code class="computeroutput"><span class="identifier">make_shared</span></code>
        can be implemented using <code class="computeroutput"><span class="identifier">allocate_shared</span></code>
        with <code class="computeroutput"><span class="identifier">default_allocator</span></code>.
      </p>
<pre class="programlisting"><span class="keyword">template</span><span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">T</span><span class="special">,</span> <span class="keyword">class</span><span class="special">...</span> <span class="identifier">Args</span><span class="special">&gt;</span>
<span class="identifier">enable_if_t</span><span class="special">&lt;!</span><span class="identifier">is_array_v</span><span class="special">&lt;</span><span class="identifier">T</span><span class="special">&gt;,</span> <span class="identifier">shared_ptr</span><span class="special">&lt;</span><span class="identifier">T</span><span class="special">&gt;</span> <span class="special">&gt;</span>
<span class="identifier">make_shared</span><span class="special">(</span><span class="identifier">Args</span><span class="special">&amp;&amp;...</span> <span class="identifier">args</span><span class="special">)</span>
<span class="special">{</span>
    <span class="keyword">return</span> <span class="identifier">allocate_shared</span><span class="special">&lt;</span><span class="identifier">T</span><span class="special">&gt;(</span><span class="identifier">boost</span><span class="special">::</span><span class="identifier">default_allocator</span><span class="special">&lt;</span><span class="identifier">remove_cv_t</span><span class="special">&lt;</span><span class="identifier">T</span><span class="special">&gt;</span> <span class="special">&gt;(),</span>
        <span class="identifier">std</span><span class="special">::</span><span class="identifier">forward</span><span class="special">&lt;</span><span class="identifier">Args</span><span class="special">&gt;(</span><span class="identifier">args</span><span class="special">)...);</span>
<span class="special">}</span>
</pre>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="core.default_allocator.reference"></a><a class="link" href="default_allocator.html#core.default_allocator.reference" title="Reference">Reference</a>
</h3></div></div></div>
<pre class="programlisting"><span class="keyword">namespace</span> <span class="identifier">boost</span> <span class="special">{</span>

<span class="keyword">template</span><span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">T</span><span class="special">&gt;</span>
<span class="keyword">struct</span> <span class="identifier">default_allocator</span> <span class="special">{</span>
    <span class="keyword">typedef</span> <span class="identifier">T</span> <span class="identifier">value_type</span><span class="special">;</span>
    <span class="keyword">typedef</span> <span class="identifier">T</span><span class="special">*</span> <span class="identifier">pointer</span><span class="special">;</span>
    <span class="keyword">typedef</span> <span class="keyword">const</span> <span class="identifier">T</span><span class="special">*</span> <span class="identifier">const_pointer</span><span class="special">;</span>
    <span class="keyword">typedef</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">add_lvalue_reference_t</span><span class="special">&lt;</span><span class="identifier">T</span><span class="special">&gt;</span> <span class="identifier">reference</span><span class="special">;</span>
    <span class="keyword">typedef</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">add_lvalue_reference_t</span><span class="special">&lt;</span><span class="keyword">const</span> <span class="identifier">T</span><span class="special">&gt;</span> <span class="identifier">const_reference</span><span class="special">;</span>
    <span class="keyword">typedef</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">size_t</span> <span class="identifier">size_type</span><span class="special">;</span>
    <span class="keyword">typedef</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">ptrdiff_t</span> <span class="identifier">difference_type</span><span class="special">;</span>
    <span class="keyword">typedef</span> <span class="emphasis"><em>true_type</em></span> <span class="identifier">propagate_on_container_move_assignment</span><span class="special">;</span>
    <span class="keyword">typedef</span> <span class="emphasis"><em>true_type</em></span> <span class="identifier">is_always_equal</span><span class="special">;</span>

    <span class="keyword">template</span><span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">U</span><span class="special">&gt;</span>
    <span class="keyword">struct</span> <span class="identifier">rebind</span> <span class="special">{</span>
        <span class="keyword">typedef</span> <span class="identifier">default_allocator</span><span class="special">&lt;</span><span class="identifier">U</span><span class="special">&gt;</span> <span class="identifier">other</span><span class="special">;</span>
    <span class="special">};</span>

    <span class="keyword">constexpr</span> <span class="identifier">default_allocator</span><span class="special">()</span> <span class="special">=</span> <span class="keyword">default</span><span class="special">;</span>

    <span class="keyword">template</span><span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">U</span><span class="special">&gt;</span>
    <span class="keyword">constexpr</span> <span class="identifier">default_allocator</span><span class="special">(</span><span class="keyword">const</span> <span class="identifier">default_allocator</span><span class="special">&lt;</span><span class="identifier">U</span><span class="special">&gt;&amp;)</span> <span class="keyword">noexcept</span> <span class="special">{</span> <span class="special">}</span>

    <span class="keyword">constexpr</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">size_t</span> <span class="identifier">max_size</span><span class="special">()</span> <span class="keyword">const</span> <span class="keyword">noexcept</span><span class="special">;</span>
    <span class="identifier">T</span><span class="special">*</span> <span class="identifier">allocate</span><span class="special">(</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">size_t</span> <span class="identifier">n</span><span class="special">);</span>
    <span class="keyword">void</span> <span class="identifier">deallocate</span><span class="special">(</span><span class="identifier">T</span><span class="special">*</span> <span class="identifier">p</span><span class="special">,</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">size_t</span><span class="special">);</span>
<span class="special">};</span>

<span class="keyword">template</span><span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">T</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">U</span><span class="special">&gt;</span>
<span class="keyword">constexpr</span> <span class="keyword">bool</span> <span class="keyword">operator</span><span class="special">==(</span><span class="keyword">const</span> <span class="identifier">default_allocator</span><span class="special">&lt;</span><span class="identifier">T</span><span class="special">&gt;&amp;,</span>
    <span class="keyword">const</span> <span class="identifier">default_allocator</span><span class="special">&lt;</span><span class="identifier">U</span><span class="special">&gt;&amp;)</span> <span class="keyword">noexcept</span><span class="special">;</span>

<span class="keyword">template</span><span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">T</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">U</span><span class="special">&gt;</span>
<span class="keyword">constexpr</span> <span class="keyword">bool</span> <span class="keyword">operator</span><span class="special">!=(</span><span class="keyword">const</span> <span class="identifier">default_allocator</span><span class="special">&lt;</span><span class="identifier">T</span><span class="special">&gt;&amp;,</span>
    <span class="keyword">const</span> <span class="identifier">default_allocator</span><span class="special">&lt;</span><span class="identifier">U</span><span class="special">&gt;&amp;)</span> <span class="keyword">noexcept</span><span class="special">;</span>

<span class="special">}</span> <span class="comment">/* boost */</span>
</pre>
<div class="section">
<div class="titlepage"><div><div><h4 class="title">
<a name="core.default_allocator.reference.members"></a><a class="link" href="default_allocator.html#core.default_allocator.reference.members" title="Members">Members</a>
</h4></div></div></div>
<div class="variablelist">
<p class="title"><b></b></p>
<dl class="variablelist">
<dt><span class="term"><code class="computeroutput"><span class="keyword">constexpr</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">size_t</span>
            <span class="identifier">max_size</span><span class="special">()</span>
            <span class="keyword">const</span> <span class="keyword">noexcept</span><span class="special">;</span></code></span></dt>
<dd><div class="variablelist">
<p class="title"><b></b></p>
<dl class="variablelist">
<dt><span class="term">Returns</span></dt>
<dd><p>
                      The largest value <code class="computeroutput"><span class="identifier">N</span></code>
                      for which the call <code class="computeroutput"><span class="identifier">allocate</span><span class="special">(</span><span class="identifier">N</span><span class="special">)</span></code> might succeed.
                    </p></dd>
</dl>
</div></dd>
<dt><span class="term"><code class="computeroutput"><span class="identifier">T</span><span class="special">*</span>
            <span class="identifier">allocate</span><span class="special">(</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">size_t</span> <span class="identifier">n</span><span class="special">);</span></code></span></dt>
<dd><div class="variablelist">
<p class="title"><b></b></p>
<dl class="variablelist">
<dt><span class="term">Returns</span></dt>
<dd><p>
                      A pointer to the initial element of an array of storage of
                      size <code class="computeroutput"><span class="identifier">n</span> <span class="special">*</span>
                      <span class="keyword">sizeof</span><span class="special">(</span><span class="identifier">T</span><span class="special">)</span></code>,
                      aligned appropriately for objects of type <code class="computeroutput"><span class="identifier">T</span></code>.
                    </p></dd>
<dt><span class="term">Remarks</span></dt>
<dd><p>
                      The storage is obtained by calling <code class="computeroutput"><span class="special">::</span><span class="keyword">operator</span> <span class="keyword">new</span></code>.
                    </p></dd>
<dt><span class="term">Throws</span></dt>
<dd><p>
                      <code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">bad_alloc</span></code> if the storage
                      cannot be obtained.
                    </p></dd>
</dl>
</div></dd>
<dt><span class="term"><code class="computeroutput"><span class="keyword">void</span> <span class="identifier">deallocate</span><span class="special">(</span><span class="identifier">T</span><span class="special">*</span> <span class="identifier">p</span><span class="special">,</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">size_t</span>
            <span class="identifier">n</span><span class="special">);</span></code></span></dt>
<dd><div class="variablelist">
<p class="title"><b></b></p>
<dl class="variablelist">
<dt><span class="term">Requires</span></dt>
<dd><p>
                      <code class="computeroutput"><span class="identifier">p</span></code> shall be
                      a pointer value obtained from <code class="computeroutput"><span class="identifier">allocate</span><span class="special">()</span></code>. <code class="computeroutput"><span class="identifier">n</span></code>
                      shall equal the value passed as the first argument to the invocation
                      of <code class="computeroutput"><span class="identifier">allocate</span></code>
                      which returned <code class="computeroutput"><span class="identifier">p</span></code>.
                    </p></dd>
<dt><span class="term">Effects</span></dt>
<dd><p>
                      Deallocates the storage referenced by <code class="computeroutput"><span class="identifier">p</span></code>.
                    </p></dd>
<dt><span class="term">Remarks</span></dt>
<dd><p>
                      Uses <code class="computeroutput"><span class="special">::</span><span class="keyword">operator</span>
                      <span class="keyword">delete</span></code>.
                    </p></dd>
</dl>
</div></dd>
</dl>
</div>
</div>
<div class="section">
<div class="titlepage"><div><div><h4 class="title">
<a name="core.default_allocator.reference.operators"></a><a class="link" href="default_allocator.html#core.default_allocator.reference.operators" title="Operators">Operators</a>
</h4></div></div></div>
<div class="variablelist">
<p class="title"><b></b></p>
<dl class="variablelist">
<dt><span class="term"><code class="computeroutput"><span class="keyword">template</span><span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">T</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">U</span><span class="special">&gt;</span> <span class="keyword">constexpr</span> <span class="keyword">bool</span>
            <span class="keyword">operator</span><span class="special">==(</span><span class="keyword">const</span> <span class="identifier">default_allocator</span><span class="special">&lt;</span><span class="identifier">T</span><span class="special">&gt;&amp;,</span> <span class="keyword">const</span>
            <span class="identifier">default_allocator</span><span class="special">&lt;</span><span class="identifier">U</span><span class="special">&gt;&amp;)</span>
            <span class="keyword">noexcept</span><span class="special">;</span></code></span></dt>
<dd><div class="variablelist">
<p class="title"><b></b></p>
<dl class="variablelist">
<dt><span class="term">Returns</span></dt>
<dd><p>
                      <code class="computeroutput"><span class="keyword">true</span></code>.
                    </p></dd>
</dl>
</div></dd>
<dt><span class="term"><code class="computeroutput"><span class="keyword">template</span><span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">T</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">U</span><span class="special">&gt;</span> <span class="keyword">constexpr</span> <span class="keyword">bool</span>
            <span class="keyword">operator</span><span class="special">!=(</span><span class="keyword">const</span> <span class="identifier">default_allocator</span><span class="special">&lt;</span><span class="identifier">T</span><span class="special">&gt;&amp;,</span> <span class="keyword">const</span>
            <span class="identifier">default_allocator</span><span class="special">&lt;</span><span class="identifier">U</span><span class="special">&gt;&amp;)</span>
            <span class="keyword">noexcept</span><span class="special">;</span></code></span></dt>
<dd><div class="variablelist">
<p class="title"><b></b></p>
<dl class="variablelist">
<dt><span class="term">Returns</span></dt>
<dd><p>
                      <code class="computeroutput"><span class="keyword">false</span></code>.
                    </p></dd>
</dl>
</div></dd>
</dl>
</div>
</div>
</div>
</div>
<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
<td align="left"></td>
<td align="right"><div class="copyright-footer">Copyright © 2014 Peter Dimov<br>Copyright © 2014 Glen Fernandes<br>Copyright © 2014 Andrey Semashev<p>
        Distributed under the <a href="http://boost.org/LICENSE_1_0.txt" target="_top">Boost
        Software License, Version 1.0</a>.
      </p>
</div></td>
</tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="cmath.html"><img src="../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../index.html"><img src="../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="demangle.html"><img src="../../../../../doc/src/images/next.png" alt="Next"></a>
</div>
</body>
</html>
